package com.vueapi.controller.web;

import com.vueapi.service.HjArticleService;
import com.vueapi.utils.ResultUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Classname WebBlogController
 * @Description TODO
 * @Created by 赵宏建
 * @Date 2022/9/27 11:10
 * @Version 1.0.0
 */
@RestController
@RequestMapping("/web/blog")
public class WebBlogController {

    @Resource
    private HjArticleService articleService;

    @PostMapping("/test")
    public ResultUtils test(@RequestBody String test_param) {
        System.out.println(test_param);
        return ResultUtils.success("POST测试成功");
    }

    @GetMapping("/getArticles")
    public ResultUtils list(@RequestParam(defaultValue = "1") Integer pageNum,
                            @RequestParam(defaultValue = "10") Integer pageSize,
                            @RequestParam(required = false) Integer categoryId,
                            @RequestParam(required = false, defaultValue = "") String title) {
        return articleService.listPage(pageNum, pageSize, title, categoryId);
    }

    @GetMapping("/getArticleByCategoryId")
    public ResultUtils getArticleByCategoryId(@RequestParam(defaultValue = "1") Integer pageNum,
                                              @RequestParam(defaultValue = "10") Integer pageSize,
                                              @RequestParam(required = false, defaultValue = "") Integer categoryId) {
        return articleService.getArticleByCategoryId(pageNum, pageSize, categoryId);
    }

    @GetMapping("/getArticleByTagId")
    public ResultUtils getArticleByTagId(@RequestParam(defaultValue = "1") Integer pageNum,
                                         @RequestParam(defaultValue = "10") Integer pageSize,
                                         @RequestParam(required = false, defaultValue = "") Integer tagId) {
        return articleService.getArticleByTagId(pageNum, pageSize, tagId);
    }

    @GetMapping("getArticleById/{id}")
    public ResultUtils getArticleById(@PathVariable("id") Integer id) {
        return ResultUtils.success(articleService.getArticleById(id));
    }

    @GetMapping("/getNewsArticle")
    public ResultUtils getNewsArticle() {
        return articleService.getNewsArticle();
    }

}
